package com.vipshop.util.bitmap;



import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.vipshop.util.Download;
import com.vipshop.util.factory.ImageUrlFactory;
import com.vipshop.view.interfaces.DialogLisetener;
import com.vipshop.vip.model.BrandResult;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.ViewFlipper;

/**
 * <b>下载器</b>
 * @author simon
 *
 */
public class DownManager implements DialogLisetener{

	private static DownManager manager;

	private Activity mContext;

	public DownManager(Activity context) {
		mContext = context;
	}
	public static DownManager getInstance(Activity context){
		if(manager == null)
			manager = new DownManager(context);
		return manager;
	}
	@Override
	public void updateView(View view) {
		// TODO Auto-generated method stub

	}

	/**
	 * <b>下载</b>
	 * @param ad
	 * @param view
	 * @return
	 */
//	public static Download DownloadImage(AdBean ad, View view){
//		Download download = new Download();
//		download.url = new URLHelper(ad.getPic4());
//		download.filename = PHOTO_DOWNLOAD_DIRECTORY+ad.getAdtype()+"/"+download.url.filename;
//		download.view = view;
//		return download;
//	}

	/**
	 *
	 */
	public static Download createDownload(BrandResult ad, View view){
		Download download = new Download();
		String imageUrl = ImageUrlFactory.notify(ad.getIndex_image(), ImageUrlFactory.GOODS);
		System.out.println(imageUrl);
		String[] url =  imageUrl.split("@");
		String fileUrl=null;
		String backupUrl;
		if(url.length == 2){
			fileUrl = url[0];
			backupUrl = url[1];
		}else{
			backupUrl = null;
		}
		//压缩地址：http://pic1.vipshop.com/upload/brand/201207/2012071111210684681_270x332_80.jpg
		//原地址：http://img1.vipshop.com/upload/brand/201207/2012071111210684681.jpg

		System.out.println("压缩地址："+fileUrl);
		System.out.println("原地址："+backupUrl);
		download.url = new URLHelper(backupUrl);
		download.filename = "down_"+"/"+download.url.filename;
		download.view = view;
		return download;
	}

}
